PSCI: Replace macros by static inline functions
authorAntonio Nino Diaz <[email protected]>
Wed, 18 Jul 2018 10:57:21 +0000 (11:57 +0100)
committerAntonio Nino Diaz <[email protected]>
Fri, 20 Jul 2018 12:27:31 +0000 (13:27 +0100)
Fix MISRA C-2012 Directive 4.9 and Rule 21.1 defects.

Change-Id: I96c216317d38741ee632d2640cd7b36e6723d5c2
Signed-off-by: Antonio Nino Diaz <[email protected]>
include/lib/psci/psci.h
lib/psci/psci_common.c
lib/psci/psci_on.c
lib/psci/psci_private.h

index 06434f9e5ddbaccc6a72d68c5fa1912c2c95f0f1..1aa963327ca371632261d0a716351a7299914c39 100644 (file)
@@ -1,11 +1,11 @@
 /*
- * Copyright (c) 2013-2017, ARM Limited and Contributors. All rights reserved.
+ * Copyright (c) 2013-2018, ARM Limited and Contributors. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  */
 
-#ifndef __PSCI_H__
-#define __PSCI_H__
+#ifndef PSCI_H
+#define PSCI_H
 
 #include <bakery_lock.h>
 #include <bl_common.h>
@@ -71,9 +71,6 @@
 #define PSCI_MEM_CHK_RANGE_AARCH32     U(0x84000014)
 #define PSCI_MEM_CHK_RANGE_AARCH64     U(0xc4000014)
 
-/* Macro to help build the psci capabilities bitfield */
-#define define_psci_cap(x)             (U(1) << (x & U(0x1f)))
-
 /*
  * Number of PSCI calls (above) implemented
  */
 #define PSTATE_TYPE_POWERDOWN  U(0x1)
 #define PSTATE_TYPE_MASK       U(0x1)
 
-#define psci_get_pstate_id(pstate)     (((pstate) >> PSTATE_ID_SHIFT) & \
-                                       PSTATE_ID_MASK)
-#define psci_get_pstate_type(pstate)   (((pstate) >> PSTATE_TYPE_SHIFT) & \
-                                       PSTATE_TYPE_MASK)
-#define psci_check_power_state(pstate) ((pstate) & PSTATE_VALID_MASK)
-
 /*******************************************************************************
  * PSCI CPU_FEATURES feature flag specific defines
  ******************************************************************************/
 #include <stdint.h>
 #include <types.h>
 
+/* Function to help build the psci capabilities bitfield */
+
+static inline unsigned int define_psci_cap(unsigned int x)
+{
+       return U(1) << (x & U(0x1f));
+}
+
+
+/* Power state helper functions */
+
+static inline unsigned int psci_get_pstate_id(unsigned int power_state)
+{
+       return ((power_state) >> PSTATE_ID_SHIFT) & PSTATE_ID_MASK;
+}
+
+static inline unsigned int psci_get_pstate_type(unsigned int power_state)
+{
+       return ((power_state) >> PSTATE_TYPE_SHIFT) & PSTATE_TYPE_MASK;
+}
+
+static inline unsigned int psci_check_power_state(unsigned int power_state)
+{
+       return ((power_state) & PSTATE_VALID_MASK);
+}
+
 /*
  * These are the states reported by the PSCI_AFFINITY_INFO API for the specified
  * CPU. The definitions of these states can be found in Section 5.7.1 in the
@@ -218,24 +234,30 @@ typedef uint8_t plat_local_state_t;
 #define PSCI_LOCAL_STATE_RUN   U(0)
 
 /*
- * Macro to test whether the plat_local_state is RUN state
+ * Function to test whether the plat_local_state is RUN state
  */
-#define is_local_state_run(plat_local_state) \
-                       ((plat_local_state) == PSCI_LOCAL_STATE_RUN)
+static inline int is_local_state_run(unsigned int plat_local_state)
+{
+       return (plat_local_state == PSCI_LOCAL_STATE_RUN) ? 1 : 0;
+}
 
 /*
- * Macro to test whether the plat_local_state is RETENTION state
+ * Function to test whether the plat_local_state is RETENTION state
  */
-#define is_local_state_retn(plat_local_state) \
-                       (((plat_local_state) > PSCI_LOCAL_STATE_RUN) && \
-                       ((plat_local_state) <= PLAT_MAX_RET_STATE))
+static inline int is_local_state_retn(unsigned int plat_local_state)
+{
+       return ((plat_local_state > PSCI_LOCAL_STATE_RUN) &&
+               (plat_local_state <= PLAT_MAX_RET_STATE)) ? 1 : 0;
+}
 
 /*
- * Macro to test whether the plat_local_state is OFF state
+ * Function to test whether the plat_local_state is OFF state
  */
-#define is_local_state_off(plat_local_state) \
-                       (((plat_local_state) > PLAT_MAX_RET_STATE) && \
-                       ((plat_local_state) <= PLAT_MAX_OFF_STATE))
+static inline int is_local_state_off(unsigned int plat_local_state)
+{
+       return ((plat_local_state > PLAT_MAX_RET_STATE) &&
+               (plat_local_state <= PLAT_MAX_OFF_STATE)) ? 1 : 0;
+}
 
 /*****************************************************************************
  * This data structure defines the representation of the power state parameter
@@ -339,4 +361,4 @@ void psci_entrypoint(void) __deprecated;
 
 #endif /*__ASSEMBLY__*/
 
-#endif /* __PSCI_H__ */
+#endif /* PSCI_H */
index 2220a745cd6e01988e7e7f293c139e1cd90bde6e..bb228b259b09346c3fb94342306ca7825b35bb2f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013-2017, ARM Limited and Contributors. All rights reserved.
+ * Copyright (c) 2013-2018, ARM Limited and Contributors. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  */
@@ -93,11 +93,19 @@ typedef enum plat_local_state_type {
        STATE_TYPE_OFF
 } plat_local_state_type_t;
 
-/* The macro used to categorize plat_local_state. */
-#define find_local_state_type(plat_local_state)                                        \
-               ((plat_local_state) ? ((plat_local_state > PLAT_MAX_RET_STATE)  \
-               ? STATE_TYPE_OFF : STATE_TYPE_RETN)                             \
-               : STATE_TYPE_RUN)
+/* Function used to categorize plat_local_state. */
+static plat_local_state_type_t find_local_state_type(plat_local_state_t state)
+{
+       if (state != 0U) {
+               if (state > PLAT_MAX_RET_STATE) {
+                       return STATE_TYPE_OFF;
+               } else {
+                       return STATE_TYPE_RETN;
+               }
+       } else {
+               return STATE_TYPE_RUN;
+       }
+}
 
 /******************************************************************************
  * Check that the maximum retention level supported by the platform is less
index 53b044ecff1da625be94996eccdbc9a3283024c8..325346e29d36485b9771fe65619ed914b3357e47 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013-2017, ARM Limited and Contributors. All rights reserved.
+ * Copyright (c) 2013-2018, ARM Limited and Contributors. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  */
 #include <stddef.h>
 #include "psci_private.h"
 
+/*
+ * Helper functions for the CPU level spinlocks
+ */
+static inline void psci_spin_lock_cpu(int idx)
+{
+       spin_lock(&psci_cpu_pd_nodes[idx].cpu_lock);
+}
+
+static inline void psci_spin_unlock_cpu(int idx)
+{
+       spin_unlock(&psci_cpu_pd_nodes[idx].cpu_lock);
+}
+
 /*******************************************************************************
  * This function checks whether a cpu which has been requested to be turned on
  * is OFF to begin with.
index d452e2ae070f0c3391ab5d2bc2368b00b64ffd44..08938846369ddebc45adf35e28c250bd7d18aee0 100644 (file)
@@ -4,8 +4,8 @@
  * SPDX-License-Identifier: BSD-3-Clause
  */
 
-#ifndef __PSCI_PRIVATE_H__
-#define __PSCI_PRIVATE_H__
+#ifndef PSCI_PRIVATE_H
+#define PSCI_PRIVATE_H
 
 #include <arch.h>
 #include <bakery_lock.h>
                        define_psci_cap(PSCI_MEM_CHK_RANGE_AARCH64))
 
 /*
- * Helper macros to get/set the fields of PSCI per-cpu data.
+ * Helper functions to get/set the fields of PSCI per-cpu data.
  */
-#define psci_set_aff_info_state(_aff_state) \
-               set_cpu_data(psci_svc_cpu_data.aff_info_state, _aff_state)
-#define psci_get_aff_info_state() \
-               get_cpu_data(psci_svc_cpu_data.aff_info_state)
-#define psci_get_aff_info_state_by_idx(_idx) \
-               get_cpu_data_by_index(_idx, psci_svc_cpu_data.aff_info_state)
-#define psci_set_aff_info_state_by_idx(_idx, _aff_state) \
-               set_cpu_data_by_index(_idx, psci_svc_cpu_data.aff_info_state,\
-                                       _aff_state)
-#define psci_get_suspend_pwrlvl() \
-               get_cpu_data(psci_svc_cpu_data.target_pwrlvl)
-#define psci_set_suspend_pwrlvl(_target_lvl) \
-               set_cpu_data(psci_svc_cpu_data.target_pwrlvl, _target_lvl)
-#define psci_set_cpu_local_state(_state) \
-               set_cpu_data(psci_svc_cpu_data.local_state, _state)
-#define psci_get_cpu_local_state() \
-               get_cpu_data(psci_svc_cpu_data.local_state)
-#define psci_get_cpu_local_state_by_idx(_idx) \
-               get_cpu_data_by_index(_idx, psci_svc_cpu_data.local_state)
-
-/*
- * Helper macros for the CPU level spinlocks
- */
-#define psci_spin_lock_cpu(_idx) spin_lock(&psci_cpu_pd_nodes[_idx].cpu_lock)
-#define psci_spin_unlock_cpu(_idx) spin_unlock(&psci_cpu_pd_nodes[_idx].cpu_lock)
-
-/* Helper macro to identify a CPU standby request in PSCI Suspend call */
-#define is_cpu_standby_req(_is_power_down_state, _retn_lvl) \
-               (((!(_is_power_down_state)) && ((_retn_lvl) == 0)) ? 1 : 0)
+static inline void psci_set_aff_info_state(aff_info_state_t aff_state)
+{
+       set_cpu_data(psci_svc_cpu_data.aff_info_state, aff_state);
+}
+
+static inline aff_info_state_t psci_get_aff_info_state(void)
+{
+       return get_cpu_data(psci_svc_cpu_data.aff_info_state);
+}
+
+static inline aff_info_state_t psci_get_aff_info_state_by_idx(int idx)
+{
+       return get_cpu_data_by_index((unsigned int)idx,
+                                    psci_svc_cpu_data.aff_info_state);
+}
+
+static inline void psci_set_aff_info_state_by_idx(int idx,
+                                                 aff_info_state_t aff_state)
+{
+       set_cpu_data_by_index((unsigned int)idx,
+                             psci_svc_cpu_data.aff_info_state, aff_state);
+}
+
+static inline unsigned int psci_get_suspend_pwrlvl(void)
+{
+       return get_cpu_data(psci_svc_cpu_data.target_pwrlvl);
+}
+
+static inline void psci_set_suspend_pwrlvl(unsigned int target_lvl)
+{
+       set_cpu_data(psci_svc_cpu_data.target_pwrlvl, target_lvl);
+}
+
+static inline void psci_set_cpu_local_state(plat_local_state_t state)
+{
+       set_cpu_data(psci_svc_cpu_data.local_state, state);
+}
+
+static inline plat_local_state_t psci_get_cpu_local_state(void)
+{
+       return get_cpu_data(psci_svc_cpu_data.local_state);
+}
+
+static inline plat_local_state_t psci_get_cpu_local_state_by_idx(int idx)
+{
+       return get_cpu_data_by_index((unsigned int)idx,
+                                    psci_svc_cpu_data.local_state);
+}
+
+/* Helper function to identify a CPU standby request in PSCI Suspend call */
+static inline int is_cpu_standby_req(unsigned int is_power_down_state,
+                                    unsigned int retn_lvl)
+{
+       return ((is_power_down_state == 0U) && (retn_lvl == 0U)) ? 1 : 0;
+}
 
 /*******************************************************************************
  * The following two data structures implement the power domain tree. The tree
@@ -276,4 +302,4 @@ u_register_t psci_stat_count(u_register_t target_cpu,
 int psci_mem_protect(unsigned int enable);
 int psci_mem_chk_range(uintptr_t base, u_register_t length);
 
-#endif /* __PSCI_PRIVATE_H__ */
+#endif /* PSCI_PRIVATE_H */